package com.ibeetl.admin.api.web;

import com.ibeetl.admin.api.entity.Travel_video_list;
import com.ibeetl.admin.api.service.TravelVideoService;
import com.ibeetl.admin.core.web.JsonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@Tag(
        name = "TravelVideoController")
public class TravelVideoController {
    private final Log log = LogFactory.getLog(this.getClass());
    private static final String MODEL = "/api/travel_video_list";
    @Resource
    private TravelVideoService travelVideoService;

    @Operation(
            summary = "新增景点视频"
    )
    @PostMapping(MODEL + "/add.json")
    @CrossOrigin
    public JsonResult<Travel_video_list> add(Travel_video_list travel_video) {
        if(travelVideoService.saveData(travel_video)){
            Long videoId = travelVideoService.queryNewIdByAttractionId(travel_video.getAttractionId(),travel_video.getUserId());
            travel_video.setVideoId(videoId);
            return JsonResult.success(travel_video);
        }else{
            return JsonResult.failMessage("新增失败！");
        }

    }
    @Operation(
            summary = "更新景点视频"
    )
    @PostMapping(MODEL + "/update.json")
    @CrossOrigin
    public JsonResult<Travel_video_list> update(Travel_video_list travel_video) {
        travelVideoService.update(travel_video);
        return JsonResult.success(travel_video);
    }
    @Operation(
            summary = "删除景点视频"
    )
    @PostMapping(MODEL + "/deleteById.json")
    @CrossOrigin
    public JsonResult<Travel_video_list> deleteById(Long videoId) {
        travelVideoService.delete(videoId,3);
        // TODO 删除文件夹下的文件
        return JsonResult.success();
    }

    @Operation(
            summary = "根据路线ID查询景点视频"
    )
    @PostMapping(MODEL + "/queryByAttractionId.json")
    @CrossOrigin
    public JsonResult<List> queryByAttractionId(Long attractionId,Long userId) {
        List<Travel_video_list>  travel_videos  = travelVideoService.queryByAttractionId(attractionId,userId);
        return JsonResult.success(travel_videos);
    }
    @Operation(
            summary = "根据景点ID查询景点视频"
    )
    @PostMapping(MODEL + "/queryByAttsId.json")
    @CrossOrigin
    public JsonResult<List> queryByAttsId(Long attsId,Long userId) {
        List<Travel_video_list>  travel_videos  = travelVideoService.queryByAttsId(attsId,userId);
        return JsonResult.success(travel_videos);
    }

    @Operation(
            summary = "根据视频ID查询景点视频"
    )
    @PostMapping(MODEL + "/queryById.json")
    @CrossOrigin
    public JsonResult<Travel_video_list> queryById(Long videoId) {
        Travel_video_list travel_video  = travelVideoService.queryById(videoId);
        return JsonResult.success(travel_video);
    }

}
